package com.WaVel.service.impl;

import com.Emplyment.entity.Advertisement;
import com.Emplyment.vo.AdvertisementVo;
import com.WaVel.mapper.AdvertisementMapper;
import com.WaVel.service.AdvertisementService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@Slf4j
public class AdvertisementServiceImpl implements AdvertisementService {

    @Autowired
    private AdvertisementMapper advertisementMapper;

    /**
     * 查询广告所有信息
     * @return
     */
    @Override
    public List<AdvertisementVo> getAdvertisement() {
        List<AdvertisementVo> advertisement = advertisementMapper.getAdvertisement();
        return advertisement;
    }

    @Override
    public void insertAdvertisement(AdvertisementVo advertisementVo) {
        if (advertisementVo == null){
            throw new RuntimeException("广告新闻不能为空");
        }
        Advertisement advertisement = new Advertisement();
        BeanUtils.copyProperties(advertisementVo, advertisement);
        advertisementMapper.insertAdvertisement(advertisement);
    }

    @Override
    public void updateAdvertisement(AdvertisementVo advertisementVo) {
        if (advertisementVo == null){
            throw new RuntimeException("广告新闻不能为空");
        }
        Advertisement advertisement = new Advertisement();
        BeanUtils.copyProperties(advertisementVo, advertisement);
        advertisementMapper.updateAdvertisement(advertisement);
    }

    @Override
    public void deleteAdvertisement(Integer id) {
        advertisementMapper.deleteAdvertisement(id);
    }
}
